package asf.core
{
	import br.pedromoraes.btween.BTween;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	import flash.utils.*;

	public class Layer extends Sprite
	{
		public var node:XML;
		private var darkTransform:ColorTransform;
		
		public function Layer( )
		{
			super( );
			darkTransform = new ColorTransform( 1, 1, 1, 1, 0, 0, 0, 0 );
		}
		
		public override function addChild(child:DisplayObject):DisplayObject
		{
			var res:DisplayObject = super.addChild( child );
			
			this.dispatchEvent( new Event( Event.RESIZE ) );
			
			return res;
		}
		
		public override function toString( ):String
		{
			return "[Layer " + this.name + "]";
		}
		
		public function goDark( amount:Number = 0.2, clear:Boolean = false ):void
		{
			BTween.make( 300 ).start( { target: this, dark: ( !clear )? amount: 1 } );
		}
		
		public function set dark( value:Number ):void
		{
			darkTransform.redMultiplier = value;
			darkTransform.greenMultiplier = value;
			darkTransform.blueMultiplier = value;
			darkTransform.alphaOffset = ( 1 - value ) * 255;
			
			this.transform.colorTransform = darkTransform;
		}
		
		public function get dark( ):Number
		{
			return darkTransform.redMultiplier;
		}
	}
}